package com.edu.controller;

import com.edu.domain.User;
import com.edu.service.UserService;
import com.edu.service.impl.UserServiceImpl;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户模块的控制层
 * 描述：
 * 创建人：飘
 * 创建时间：2024/10/31
 **/
public class UserController {

    private UserService userService=new UserServiceImpl();
    public Object saveUser(HttpServletRequest request)
    {
        //userid,password,username,usersex
        //接地址栏中参数的值
        String userid=request.getParameter("userid");
        String password=request.getParameter("password");
        String username=request.getParameter("username");
        //把字符串的数转成int
        int usersex=Integer.parseInt(request.getParameter("usersex"));
       //  public User(String userId, String password, String userName, int userSex, String userImg, int delTag)
        User user=new User(userid,password,username, usersex,null,0 );
        //调用业务层中用户添加方法
        int result=this.userService.saveUser(user);
        return result;
    }
    public Object getUserByIdByPass(HttpServletRequest request)
    {
        String userid=request.getParameter("userid");
        String password=request.getParameter("password");
        User user=new User(userid,password,null, 0,null,0 );

        User user1=this.userService.getUserByIdByPass(user);
        if(user1!=null)
        {
            request.getSession().setAttribute("user",user1);
        }
        return user1;
    }
    public Object getUserById(HttpServletRequest request)
    {
        String userid=request.getParameter("userid");
        return this.userService.getUserById(userid);
    }
}
